package com.hskn.hss.module.tlequipmodel.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.domain.BaseEntity;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.tlcostdateil.mapper.TlCostDateilMapper;
import com.hskn.hss.module.tlequip.entity.TlEquip;
import com.hskn.hss.module.tlequipmodel.entity.TlEquipmodel;
import com.hskn.hss.module.tlequipmodel.mapper.TlEquipmodelMapper;
import com.hskn.hss.module.tlequipmodel.service.ITlEquipmodelService;
import com.hskn.hss.utils.Tools;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-11
 */
@Api(tags = {"-tl_equipmodel"},description = "设备型号API")
@Slf4j
@RestController
@RequestMapping("/hss/tlequipmodel")
public class TlEquipmodelController {

    @Autowired
    ITlEquipmodelService tlEquipmodelService;

    @SysLog(businessType = BusinessType.INSERT, tableName = "tl_equipmodel", bean = TlEquipmodel.class, beanMapper = TlEquipmodelMapper.class, names = "equipmodel")
    @ApiOperation(value="新增",notes = "设备型号、设备类型、厂商、协议不能为空")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "equipmodel",value = "设备型号名称",dataType = "string",paramType = "query",defaultValue = "",required = true),
            @ApiImplicitParam(name = "equiptypeid",value = "设备类型ID",dataType = "string",paramType = "query",defaultValue = "",required = true),
            @ApiImplicitParam(name = "manufacturerid",value = "厂商ID",dataType = "string",paramType = "query",defaultValue = "",required = true),
            @ApiImplicitParam(name = "agreement",value = "协议名称",dataType = "string",paramType = "query",defaultValue = "",required = true),
            @ApiImplicitParam(name = "orders",value = "常用指令",dataType = "string",paramType = "query",defaultValue = "",required = true)
    })
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public AjaxResult<Object> insert(@RequestBody @Validated TlEquipmodel tlEquipmodel, HttpServletRequest request) {
        try {
            return tlEquipmodelService.insert(tlEquipmodel);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "tl_equipmodel", idKey = "id", bean = TlEquipmodel.class, beanMapper = TlEquipmodelMapper.class, names = "equipmodel")
    @ApiOperation(value="修改",notes = "设备型号、设备类型、厂商、协议不能为空")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param",dataType = "string",paramType = "body",defaultValue = "",required = true,
                    value = "id:设备型号ID\n\r" +
                            "equipmodel:设备型号名称(String)\n\r"+
                            "equiptypeid:设备类型ID(String)\n\r"+
                            "manufacturerid:厂商ID(String)\n\r"+
                            "agreement:协议名称(String)\n\r"+
                            "orders:常用指令(String)"
                            )
    })
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return tlEquipmodelService.update(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "tl_equipmodel", idKey = "ids", bean = TlEquipmodel.class, beanMapper = TlEquipmodelMapper.class, names = "equipmodel")
    @ApiOperation(value = "批量更新接口", notes = "批量更新")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = TlEquipmodel.class)
    })
    @RequestMapping(value = "updatebyids", method = RequestMethod.POST)
    public AjaxResult<Object> updatebyids(@RequestBody @Validated TlEquipmodel tlEquipmodel,HttpServletRequest request) {
        try {
            return tlEquipmodelService.updatebyids(tlEquipmodel);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.DELETE, tableName = "tl_equipmodel", idKey = "id", bean = TlEquipmodel.class, beanMapper = TlEquipmodelMapper.class, names = "equipmodel")
    @RequestMapping(value = "deletebyid", method = RequestMethod.POST)
    public AjaxResult<Object> deletebyid(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return tlEquipmodelService.deletebyid(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("删除失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.DELETE, tableName = "tl_equipmodel", idKey = "ids", bean = TlEquipmodel.class, beanMapper = TlEquipmodelMapper.class, names = "equipmodel")
    @ApiOperation(value = "批量删除接口", notes = "批量删除")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = TlEquipmodel.class)
    })
    @RequestMapping(value = "deletebatchbyid", method = RequestMethod.POST)
    public AjaxResult<Object> deletebatchbyid(@RequestBody @Validated TlEquipmodel tlEquipmodel) {

        try {
            return tlEquipmodelService.deletebatchbyid(tlEquipmodel);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("删除失败，请稍后再试");
        }
    }
    @RequestMapping(value = "getSelectList", method = RequestMethod.POST)
    public AjaxResult<Object> getSelectList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        return AjaxResult.success(tlEquipmodelService.getSelectList(params));
    }

    @RequestMapping(value = "getDetail", method = RequestMethod.POST)
    public AjaxResult<Object> getDetail(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        TlEquipmodel tlEquipmodel = null;
        try {
            tlEquipmodel = tlEquipmodelService.getDetail(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
        return AjaxResult.success(tlEquipmodel);

    }

    @RequestMapping(value = "getList", method = RequestMethod.POST)
    public AjaxResult<Object> getList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            BaseEntity entity = new BaseEntity();
            JSONObject json = tlEquipmodelService.getList(entity, params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }
}

